package com.liujinghe.service.impl;

import com.liujinghe.mapper.MusicMapper;
import com.liujinghe.pojo.Music;
import com.liujinghe.pojo.MusicExample;
import com.liujinghe.service.MusicService;
import com.liujinghe.vo.QueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class MusicServiceImpl implements MusicService {

    @Autowired
    private MusicMapper musicMapper;

    @Override
    public List<Music> findAll() {
        return musicMapper.selectByExample(null);
    }

    @Override
    public Music findById(Integer id) {
        return musicMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Music> findByQueryVo(QueryVo queryVo) {

        MusicExample musicExample = new MusicExample();
        MusicExample.Criteria criteria = musicExample.createCriteria();
        //添加条件
        if(queryVo.getMusicName()!=null){
            criteria.andMusicNameLike("%"+queryVo.getMusicName()+"%");
        }
        if(queryVo.getArtistName()!=null){
            criteria.andMusicArtistNameEqualTo(queryVo.getArtistName());
        }
        if(queryVo.getSheetId()!=null){
            criteria.andSheetIdIn(Arrays.asList(queryVo.getSheetId()));
        }

        List<Music> musicList = musicMapper.selectByExample(musicExample);

        return musicList;
    }
}
